<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试结果 - 音乐考试系统</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .result-container {
            background: white;
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0,0,0,0.1);
            max-width: 800px;
            width: 100%;
        }
        .score-circle {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 42px;
            font-weight: bold;
            margin: 0 auto 20px;
            border: 5px solid white;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .result-title {
            color: #333;
            font-size: 32px;
            margin-bottom: 10px;
            text-align: center;
        }
        .result-details {
            color: #666;
            margin-bottom: 30px;
            text-align: center;
            font-size: 18px;
        }
        .btn {
            display: inline-block;
            padding: 15px 30px;
            background: #667eea;
            color: white;
            text-decoration: none;
            border-radius: 10px;
            font-weight: bold;
            transition: all 0.3s ease;
            margin: 0 10px;
            font-size: 16px;
        }
        .btn:hover {
            background: #5a6fd8;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102,126,234,0.3);
        }
        .question-review {
            margin-top: 40px;
        }
        .review-item {
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 12px;
            background: #f8f9fa;
            border-left: 5px solid #dc3545;
            transition: all 0.3s ease;
        }
        .review-item.correct {
            border-left-color: #28a745;
            background: #e8f5e8;
        }
        .review-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .user-answer { 
            color: #dc3545; 
            font-weight: bold;
            background: #ffeaea;
            padding: 2px 8px;
            border-radius: 4px;
            margin: 0 5px;
        }
        .correct-answer { 
            color: #28a745; 
            font-weight: bold;
            background: #e8f5e8;
            padding: 2px 8px;
            border-radius: 4px;
            margin: 0 5px;
        }
        .question-content { 
            font-weight: bold; 
            margin-bottom: 15px; 
            font-size: 16px;
            color: #333;
        }
        .answer-info { 
            margin: 8px 0; 
            font-size: 15px;
        }
        .btn-container { 
            text-align: center; 
            margin-top: 40px;
        }
        .performance-summary {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 20px;
            margin: 30px 0;
        }
        .performance-item {
            text-align: center;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 10px;
        }
        .performance-value {
            font-size: 32px;
            font-weight: bold;
            color: #667eea;
            margin-bottom: 5px;
        }
        .performance-label {
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="result-container">
        <div class="score-circle">{{ score }}分</div>
        <h1 class="result-title">
            {% if score >= 60 %}🎉 考试完成！{% else %}📝 继续努力！{% endif %}
        </h1>
        <div class="result-details">
            <p><strong>{{ exam.title }}</strong></p>
            <p>提交时间: {{ current_time.strftime('%Y-%m-%d %H:%M') }}</p>
        </div>
        
        <div class="performance-summary">
            <div class="performance-item">
                <div class="performance-value">{{ correct_count }}/{{ total_questions }}</div>
                <div class="performance-label">正确题数</div>
            </div>
            <div class="performance-item">
                <div class="performance-value">{{ "%.1f"|format((correct_count / total_questions * 100) if total_questions > 0 else 0) }}%</div>
                <div class="performance-label">正确率</div>
            </div>
            <div class="performance-item">
                <div class="performance-value">{{ score }}分</div>
                <div class="performance-label">最终得分</div>
            </div>
        </div>
        
        <div class="question-review">
            <h3 style="color: #333; margin-bottom: 20px; text-align: center;">📋 题目回顾</h3>
            {% for i in range(total_questions) %}
            {% set question = questions[i] %}
            {% set user_answer = answers.get('q' ~ i|string, '未作答') %}
            {% set correct_answer = question.correct %}
            {% set is_correct = user_answer == correct_answer %}
            <div class="review-item {% if is_correct %}correct{% else %}incorrect{% endif %}">
                <div class="question-content">题目 {{ i + 1 }}: {{ question.content }}</div>
                <div class="answer-info">
                    <span>你的答案: </span>
                    <span class="user-answer">{{ user_answer }}</span>
                    {% if is_correct %}
                    <span style="color: #28a745; margin-left: 10px;">✅ 正确</span>
                    {% else %}
                    <span style="color: #dc3545; margin-left: 10px;">❌ 错误</span>
                    {% endif %}
                </div>
                {% if not is_correct %}
                <div class="answer-info">
                    <span>正确答案: </span>
                    <span class="correct-answer">{{ correct_answer }}</span>
                </div>
                {% endif %}
            </div>
            {% endfor %}
        </div>
        
        <div class="btn-container">
            <a href="/dashboard" class="btn">返回主页</a>
            <a href="/results" class="btn" style="background: #28a745;">查看详细成绩</a>
        </div>
    </div>
</body>
</html>